package com.usian.article.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.api.article.AuthorControllerApi;
import com.usian.article.service.AuthorService;
import com.usian.model.article.pojos.ApAuthor;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/v1/author")
public class AuthorController implements AuthorControllerApi {
    @Autowired
    private AuthorService authorService;

    /**
     * 根据用户id查询
     * @param id
     * @return
     */
    @GetMapping("findByUserId/{id}")
    @Override
    public ApAuthor findByUserId(@PathVariable Integer id) {
        return authorService.findByUserId(id);
    }

    /**
     * 保存作者
     * @param apAuthor
     * @return
     */
    @PostMapping("save")
    @Override
    public ResponseResult save(@RequestBody ApAuthor apAuthor) {
        return authorService.add(apAuthor);
    }

    @Override
    @GetMapping("/findByName/{name}")
    public ApAuthor findByName(@PathVariable String name) {
        return authorService.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getName,name));
    }

    @Override
    @GetMapping("/one/{id}")
    public ApAuthor findById(@PathVariable Integer id) {
        return authorService.getById(id);
    }
}
